﻿using System;
using System.Web;

namespace WebConversion.Common.UrlRewriter
{
    public abstract class UrlRewriterBase : IHttpModule
    {
        public virtual void Init(HttpApplication context)
        {
            // 警告！此代码不适用于 Windows 身份验证！
            // 如果使用 Windows 身份验证，
            // 请改为 context.BeginRequest
            context.AuthorizeRequest += BaseModuleRewriterAuthorizeRequest;
        }

        public virtual void Dispose() { }

        protected virtual void BaseModuleRewriterAuthorizeRequest(object sender, EventArgs e)
        {
            var context = (HttpApplication)sender;
            Rewrite(context.Request.Path, context);
        }

        protected abstract void Rewrite(string requestedPath, HttpApplication context);
    }
}
